import { Logger, ValidationPipe } from '@nestjs/common';
import { HttpAdapterHost,NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { AppModule } from './app.module';
import { AllExceptionFilter } from './common/filters/all-exception.filter';


async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule,{cors: true});
  const options = new DocumentBuilder()
    .setTitle('超新星博客')
    .setDescription('超新星博客API文档')
    .setVersion('1.0')
    .build();
  app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
  const document = SwaggerModule.createDocument(app, options);
  const httpAdapter = app.get(HttpAdapterHost)
  const logger = new Logger()
  app.useGlobalFilters(new AllExceptionFilter(logger,httpAdapter)) 
  app.useGlobalPipes(new ValidationPipe())
  app.useStaticAssets('upload', {
    prefix: '/upload' // 一定不可以省略 '/'
  })
  SwaggerModule.setup('api', app, document);
  await app.listen(8083);
}
bootstrap();
